@layout('layouts.clearly')

@section('content')
@id('room.post')


<?php

$fields = array('house_id','area', 'garret', 'capacity',
    'internet', 'tv', 'air_condition', 'toilet',
    'price', 'electric_price', 'water_price',
    'blank', 'note'
);
if (!isset($room)) {
    $room = array();
    $house = House::find($house_id);
    foreach ($fields as $field) {
        $room[$field] = Input::old($field, '');
    }

    if (gettype($room) != 'object') {
        $room = (object) $room;
    }

    ($room->toilet == '') &&    $room->toilet = 1;

    ($room->internet == '') && $room->internet = 1;


}

$action = action('room@post');
$title = 'Thêm loại phòng';
$submit_label = 'Thêm';

if (isset($updating)) {
    $title = 'Cập nhật loại phòng';
    $submit_label = 'Cập nhật';
    $action = action('room@update', array($room->id));
}

?>

<div class="page-head">
    <h1>{{ $title }}</h1>
</div>


<div class="container page-outer">
    <div class="w550 fl-left" id="post-form-outer">
        @if ($errors->has())
        <div class="form-errors">
            <ul>
                @foreach ($fields as $f)
                {{ $errors->first($f, '<li>:message</li>') }}
                @endforeach
            </ul>
        </div>
        @endif

        <form action="{{ $action }}" method="POST" id="room-post-form">
            <fieldset>
                <legend>Thông tin cơ bản</legend>

                <div class="control-group">
                    <label for="title">Nhà trọ</label>

                    <div class="controls">
                        <input type="hidden" name="house_id" value="{{ $house->id }}">
                        <input type="text" name="house_name" id="house-name" class="w-full"
                               value="{{ $house->house_name }}" readonly="true"/>
                    </div>
                </div>

                <div class="control-group required inline">
                    <label for="area">Diện tích phòng (đơn vị m<sup>2</sup>)</label>

                    <div class="controls">
                        <input type="text" id="area" name="area" class="w100" value="{{ $room->area }}">
                    </div>
                </div>

                <div class="control-group required inline">
                    <label for="toilet">Loại nhà vệ sinh</label>

                    <div class="controls">
                        <select class="select-box" name="toilet" id="toilet">
                        <?php
                        $list = array(0 => 'Bên ngoài', 1 => 'Trong phòng');
                        foreach ($list as $val => $text ) {
                            if ($val !== $room->toilet) {
                                echo "<option value=\"$val\">$text</option>";
                            } else {
                                echo "<option value=\"$val\" selected=\"selected\">$text</option>";
                            }
                        }
                        ?>
                        </select>
                    </div>
                </div>

                <div class="control-group inline required">
                    <label for="capacity">Sức chứa (số người / phòng)</label>
                    <div class="controls">
                        <input type="text" name="capacity" id="capacity" value="{{ $room->capacity }}" class="w100"  />
                    </div>
                </div>

                <div class="control-group inline required">
                    <label for="blank">Số phòng còn trống</label>
                    <div class="controls">
                        <input type="text" name="blank" id="blank" value="{{ $room->blank }}" class="w100"  />
                    </div>
                </div>
            </fieldset>

            <fieldset>
                <legend>Thông tin thêm</legend>
                <div class="input-col">
                    <label for="garret">
                        <input type="checkbox" name="garret" id="garret" value="1"
                                {{ $room->garret ? 'checked="true"' : '' }}/> Có gác
                    </label>
                    <label for="internet">
                        <input type="checkbox" name="internet" id="internet" value="1"
                        {{ $room->internet ? 'checked="true"' : '' }}/> Internet
                    </label>

                </div>

                <div class="input-col">
                    <label for="tv">
                        <input type="checkbox" name="tv" id="tv" value="1"
                                {{ $room->tv ? 'checked="true"' : ''}}/>Có Tivi
                    </label>
                    <label for="air_condition">
                        <input type="checkbox" name="air_condition" id="air_condition" value="1"
                                {{ $room->air_condition ? 'checked="true"' : '' }} />Điều hòa/máy lạnh
                    </label>
                </div>

            </fieldset>

            <fieldset>
                <legend>Giá tiền</legend>
                <div class="control-group required">
                    <label for="price">Giá tiền phòng (đơn vị 1.000 VND)</label>
                    <div class="controls">
                        <input type="text" value="{{ $room->price }}" name="price" id="price" class="w-full" />
                    </div>
                </div>
                <div class="control-group required">
                    <label for="electric_price">Giá tiền điện (tính trên mỗi KWh, đơn vị 1.000 VND)</label>
                    <div class="controls">
                        <input type="text" value="{{ $room->electric_price }}" name="electric_price" id="electric_price" class="w-full" />
                    </div>
                </div>
                <div class="control-group required">
                    <label for="water_price">Giá tiền nước (Tính trên mỗi m <sup>3</sup>, đơn vị 1.000 VND)</label>
                    <div class="controls">
                        <input type="text" value="{{ $room->water_price }}" name="water_price" id="water_price" class="w-full" />
                    </div>
                </div>
            </fieldset>

                <div class="control-group ta-right">
                    <div class="controls">
                        {{ Form::token() }}
                        <a class="btn btn-large" href="{{ Request::referrer() }}">Hủy bỏ</a>
                        <button type="submit" class="btn btn-large btn-primary">{{ $submit_label }}</button>
                    </div>
                </div>
        </form>
    </div>
    <!-- #post-form-outer -->

    <div class="w350 fl-right">
        <div class="helper-box">
            <h3>Hướng dẫn</h3>
        </div>
    </div>
</div><!-- end page-outer -->
@endsection